package org.zihan.demo;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * 案例来源：4.1.14 服务端与客户端互传对象以及IO流顺序问题
 * Created by dwlijx on 2021/4/26.
 * connect to lijx@zjhcsoft.com
 */
public class Server {
    public static void main(String[] args) throws IOException, ClassNotFoundException {
        ServerSocket serverSocket = new ServerSocket(8888);
        Socket socket = serverSocket.accept();
        InputStream inputStream = socket.getInputStream();
        OutputStream outputStream = socket.getOutputStream();
        ObjectInputStream objectInputStream = new ObjectInputStream(inputStream);
        ObjectOutputStream objectOutputStream = new ObjectOutputStream(outputStream);
        for (int i = 0; i< 5; i++){
            Userinfo userinfo = (Userinfo) objectInputStream.readObject();
            System.out.println("服务端打印"+ (i+1) + ":" + userinfo.getId());
        }
        //todo:后面的没写完
    }
}
